/* SwingLOC - Decompiled by JCavaj
 * Visit http://www.bysoft.se/sureshot/jcavaj/
 */
package swingui;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;

import Model.LOCcounter;

import TestTools.TestTools;

public class SwingLOC extends Frame implements ActionListener
{
    private boolean inAnApplet = false;
    private FileDialog dialog;
    private TextArea display;
    private Checkbox cb3;
    private Button btnChoose;
    private Button btnClear;
    private Label Total;
    private int totalLOC = 0;
    String newline;
    DecimalFormat fmt = new DecimalFormat("00000");
    LOCcounter theLOC = new LOCcounter();
    
    public SwingLOC() {
	Panel panel = new Panel();
	cb3 = new Checkbox("Count Comments");
	cb3.setState(true);
	panel.add("West", cb3);
	btnChoose = new Button("Choose File");
	panel.add("East", btnChoose);
	btnChoose.addActionListener(this);
	this.add("North", panel);
	display = new TextArea(9, 30);
	display.setEditable(false);
	this.add("Center", display);
	Panel panel_0_ = new Panel();
	Total = new Label("Total: 0       ");
	panel_0_.add(Total);
	btnClear = new Button("Clear");
	btnClear.addActionListener(this);
	panel_0_.add("East", btnClear);
	this.add("South", panel_0_);
	this.setSize(300, 300);
	this.setVisible(true);
	btnChoose.requestFocus();
	this.addWindowListener(new WindowAdapter() {
	    public void windowClosing(WindowEvent windowevent) {
		if (inAnApplet) {
		    SwingLOC.this.setVisible(false);
		    SwingLOC.this.dispose();
		} else
		    System.exit(0);
	    }
	});
	newline = System.getProperty("line.separator");
    }
    
    public void actionPerformed(ActionEvent actionevent) {
	int i = 0;
	if (actionevent.getSource() == btnChoose) {
	    if (dialog == null)
		dialog = new FileDialog(this, "A File Dialog");
	    dialog.setVisible(true);
	    try {
		BufferedReader bufferedreader
		    = new BufferedReader(new FileReader(dialog.getDirectory()
							+ dialog.getFile()));
		theLOC.setCommentState(cb3.getState());
		i = theLOC.getLinesInFile(bufferedreader);
		bufferedreader.close();
	    } catch (IOException ioexception) {
		System.out.println(ioexception);
	    }
	    setText(fmt.format((long) i) + " " + dialog.getFile().toString());
	    TestTools.logToTest(fmt.format((long) i) + " "
				+ dialog.getFile().toString());
	    totalLOC = totalLOC + i;
	    Total.setText("Total: " + totalLOC);
	} else if (actionevent.getSource() == btnClear) {
	    totalLOC = 0;
	    Total.setText("Total: 0");
	    display.setText(" ");
	}
    }
    
    public void setText(String string) {
	display.append(string + newline);
    }

	public static boolean access$000(SwingLOC this$0) {
		// TODO Auto-generated method stub
		return false;
	}
}
